export enum ImageFeature {
  WEBP_LOSSY,
  WEBP_LOSSLESS,
  WEBP_ALPHA,
  WEBP_ANIMATION,
  JPEG_XL,
  AVIF,
}

export function checkImageSupport(feature: ImageFeature, callback: (isSupported: boolean) => void) {
  const img = new Image()
  img.onload = function () {
    callback((img.width > 0) && (img.height > 0))
  }
  img.onerror = function () {
    callback(false)
  }
  switch (feature) {
    case ImageFeature.WEBP_LOSSY:
      img.src = ''
      break
    case ImageFeature.WEBP_LOSSLESS:
      img.src = ''
      break
    case ImageFeature.WEBP_ALPHA:
      img.src = ''
      break
    case ImageFeature.WEBP_ANIMATION:
      img.src = ''
      break
    case ImageFeature.JPEG_XL:
      img.src = ''
      break
    case ImageFeature.AVIF:
      img.src = ''
      break
  }
}
